

# BitGrabber. Monitors a number of data sources for new torrents, then filters
# them based on certain characteristics, and uses a BitTorrent API to download
# the torrents.
import urllib


def getPage(url):
	return '\n'.join(urllib.urlopen(url).readlines())

class RssFinder(object):
	
	def __init__(self, handler):
		self.handler = handler
		self.handler.getPage()

class Handler(object):
	def __init__(self):
		print 'Handler constructor'
		self.url = None
		self.page = None
		
	def forceRefresh(self):
		self.page = None
	
	def getPage(self):
		if self.url is not None and self.page is not None:
			self.page = getPage(self.url)
		return self.url
	
	def isLoggedIn(self):
		return self._isLoggedIn(self.getPage())
		
	def setup(self):
		if not self.isLoggedIn():
			self.login()
	

class WhatHandler(Handler):
	
	def __init__(self):
		print 'What constructor'
		Handler.__init__(self)
		self.url = 'http://www.what.cd'
	
	def _isLoggedIn(self, page):
		print '_isLoggedIn():', len(page)
		return False
	
	def login(self):
		print 'login()'

